#ifndef CLIENT_LOGIN_H
#define CLIENT_LOGIN_H

#include "tcp_client.h"
#include <QMainWindow>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QGridLayout>
#include <QMessageBox>


class Client_login : public QMainWindow
{
    Q_OBJECT
public:
    explicit Client_login(QWidget *parent = nullptr);

    enum MsgKind{
        NAMEMSG = 0,//登录的消息
        METAMSG = 1,//上传共享文件的元数据消息
        DISCONNECT = 2,//断开连接的消息
        SHAREMSG = 3,//获取我的共享文件的消息
        DELETEMSG = 4,//删除共享文件的消息
        SEARCHMSG = 5,//搜索文件的消息
        SIGNMSG = 6,//注册的消息
        OTHERMSG = 7,//其他类型的消息
        BREAKPOINT=8, //获取文件断点的信息
        UPDATELOG=9//更新下载表的记录信息
    };
private:

    bool status;
    int port;
    QHostAddress *ServerIP;
    QString UserName;
    QTcpSocket *tcpSocket = nullptr;
    P2P_Server *p2pserver = nullptr;


    QWidget* myWidget;
    QLabel *UserNameLabel;
    QLineEdit *UserNameLineEdit;

    QLabel *UserPasswdLabel;
    QLineEdit *UserPasswdLineEdit;

    QLabel *ServerIPLabel;
    QLineEdit *ServerIPLineEdit;

    QLabel *PortLabel;
    QLineEdit *PortLineEdit;

    QPushButton *EnterBtn;
    QPushButton *SignBtn;

    QGridLayout *layout;


    MainWindow *tcpClient = nullptr;




    void FormatMsg(QString &msg, MsgKind kind);

signals:
    void enter(QString serverIp, QString username, QString password);
    void store(QString serverIp, QString username, QString password);

public slots:
    void slotEnter();
    void slotSignUp();

    void slotConnected();
    void close();
//    void slotDisconnected();
//    void DataReceived();
//    void SignConnected();
//    void SignDisconnected();
//    void SignDataReceived();

};

#endif // CLIENT_LOGIN_H
